<?php

/***
 * Fork Framework
 * Updated: 07/31/06
 *          08/01/06
 *          08/02/06
 */



class Fork
{
	private $class; //define class name for developer functions
	private $template; //define the file used for the templates


	public function __set($obj, $val) //set private vars
	{
		switch($obj)
		{
			case "class":
				$this->class = $val;
				break;
			case "template":
				$this->template = $val;
				break;
		}
	}
	
	public function __get($obj) //get private vars
	{
		switch($obj)
		{
			case "class":
				return $this->class;
				break;
			case "template":
				return $this->template;
				break;
		}
	}
	
	
	
	
	private function loop($start, $stop, $src)
	{
		for($x = $start; $x < $stop; $x++)
		{
			$src;
		}
	}
	
	public function render() //parse template file and generate page
	{
		$src = file_get_contents($this->template); //get contents of the template file
		
		//preg_match_all('#<fork jab="(.+?)">.+?</fork>#i', $src, $matches);
		preg_match_all('#<fork:(.+)?\s?((>(.+)?</fork>)|/>)#im', $src, $matches); //parse through for the Fork tags
		
		
		for($x = 0; $x < sizeof($matches[0]); $x++) //loop through and grab the functions to be used to replace Fork tags
		{
			/*if($matches[1][$x]) //handle looping
			{
				$this->loop($x);
			}*/
			$res = call_user_func(array($this->class, trim($matches[1][$x]))); //build function
			$src = preg_replace('#'.$matches[0][$x].'#is',$res, $src); //call function and perform replace of tags
		}

		echo $src; //display page
	}
	
	

}//end Fork




class functions
{

	public function getTitle()
	{
		return "this is a title";
	}
	
	public function getHeadline()
	{
		return "Frameworks are cool!";
	}

	public function getBodyText()
	{
		return "This was created using Forks!";
	}

	public function shortTag()
	{
		return "This is using short tags";
	}
}


$fork = new Fork();
$fork->class = "functions";
$fork->template = "template.php";
$fork->render();

?>














